"""CreateAdminRolePermissionTable Migration."""

from masoniteorm.migrations import Migration
import os


class CreateAdminRolePermissionTable(Migration):
    def up(self):
        """
        Run the migrations.
        """
        with self.schema.create("admin_role_permissions") as table:
            table.table_comment('角色绑定权限表')
            table.increments("id")
            table.unsigned_integer('admin_role_id', False).comment('admin_role.id')
            table.unsigned_integer('admin_permission_id', False).comment('admin_permission.id')

            table.timestamps()
            if os.getenv("DB_CONNECTION") != "sqlite":
                table.index('admin_role_id', 'inx_admin_role_id')
                table.index('admin_permission_id', 'inx_admin_permission_id')

    def down(self):
        """
        Revert the migrations.
        """
        self.schema.drop("admin_role_permissions")
